package com.rainner.admin.action;

import java.sql.SQLException;

import org.apache.struts2.convention.annotation.Action;

import com.rainner.admin.action.base.JsonAction;
import com.rainner.admin.defined.SystemDefine;
import com.rainner.admin.server.BrrowedBookServer;

public class BrrowedBookAction extends JsonAction {

	private static final long serialVersionUID = 1L;
	private final String base = "/brrowed/book";
	private BrrowedBookServer server = new BrrowedBookServer();
	private String type;
	private String bookId;
	private String readerUsername;

	@Action(base + "/{type}")
	public String brrowedBookData() throws SQLException {
		if (SystemDefine.BRROWED_BOOK.equals(type)) {
			map.put("data", server.allDataByBookID(bookId));
		} else if (SystemDefine.BRROWED_READER.equals(type)) {
			map.put("data", server.allDataByReaderUsername(readerUsername));
		}
		return MAP;
	}

	public void setBookId(String bookId) {
		this.bookId = bookId;
	}

	public void setReaderUsername(String readerUsername) {
		this.readerUsername = readerUsername;
	}

	public void setType(String type) {
		this.type = type;
	}

}
